<template>
  <el-container style="height: 100vh;">
    <el-aside :width="asideWidth" class="aside">
      <div class="avatar_box">
        <img src="../assets/logo.jpg" alt="logo" class="avatar" />
        <span v-show="!isCollapsed" class="system_name">海报设计系统</span>
      </div>
      <el-menu :default-active="activeIndex" class="el-menu-vertical-demo" @select="handleSelect">
        <el-menu-item index="1">
          <i class="el-icon-s-home"></i>
          <span v-show="!isCollapsed">首页</span>
        </el-menu-item>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-setting"></i>
            <span v-show="!isCollapsed">系统管理</span>
          </template>
          <el-menu-item index="2-1">用户管理</el-menu-item>
          <el-menu-item index="2-2">菜单管理</el-menu-item>
          <el-menu-item index="2-3">角色管理</el-menu-item>
        </el-submenu>
        <el-menu-item index="3">
          <i class="el-icon-picture-outline"></i>
          <span v-show="!isCollapsed">海报管理</span>
        </el-menu-item>
        <el-menu-item index="4">
          <i class="el-icon-files"></i>
          <span v-show="!isCollapsed">素材管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header class="header">
        <div class="header-left">
          <i class="el-icon-s-fold" v-if="!isCollapsed" @click="toggleAside"></i>
          <i class="el-icon-s-unfold" v-if="isCollapsed" @click="toggleAside"></i>
        </div>
        <div class="header-right">
          <!-- 在这里可以添加头像和个人信息按钮 -->
        </div>
      </el-header>
      <el-main class="main">Main</el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: '1', // 设置默认激活的菜单项
      isCollapsed: false, // 控制侧边栏展开和收缩的状态变量
    };
  },
  computed: {
    asideWidth() {
      return this.isCollapsed ? '64px' : '200px';
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
      // 这里可以根据 key 来处理不同的页面展示逻辑
    },
    toggleAside() {
      this.isCollapsed = !this.isCollapsed;
    }
  },
};
</script>

<style scoped>
html, body, #app {
  height: 100%;
  margin: 0;
}

.el-container {
  height: 100%;
}

.el-aside {
  background-color: #333;
  color: #fff;
  transition: width 0.3s ease; /* 添加宽度过渡效果 */
}

.avatar_box {
  display: flex;
  align-items: center;
  padding-left: 12px;
  background-color: #444;
  height: 60px; /* 与header一致 */
  border-bottom: 1px solid #555;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}

.system_name {
  font-size: 16px;
  font-weight: bold;
  color: #fff;
}

.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
  text-align: center;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  flex-grow: 1; /* 确保main部分占据剩余的高度 */
}

.toggle-icon {
  cursor: pointer;
  margin-right: 16px;
}

/* 自定义菜单样式 */
.el-menu-vertical-demo {
  background-color: #333;
  border-right: none;
}

::v-deep .el-menu-item,
::v-deep .el-submenu__title {
  background-color: #333;
  color: #fff;
}

::v-deep .el-menu-item:hover,
::v-deep .el-submenu__title:hover,
::v-deep .el-menu-item.is-active {
  background-color: #444 !important;
}
</style>
